class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int cost=INT_MAX;int profit=0;
        for(auto p:prices){
            cost=min(cost,p);
            profit=max(p-cost,profit);
        }
        return profit;
}
};
